function getDepartment(codeCountry , CboDepartment ){
   
        var requestUrl = '/GedeonMvc/department/bycountry'   ; 
              $.ajax({
        type: "GET",
        url: requestUrl,
        data: "codeCountry="+codeCountry ,
        success: function(response){ 
        $('#'+CboDepartment).html(response);
        },
        error: function(e){
        alert('Error: ' + e);
        }
        });
      
} 
 
function getProvince(codeCountry , codeDepartment , CboProvince ){
    var requestUrl = '/GedeonMvc/province/bycountryanddepartment'   ;
   
              $.ajax({
        type: "POST",
        url: requestUrl,
        data: "codeCountry="+codeCountry+"&codeDepartment="+codeDepartment ,
        success: function(response){ 
        $('#'+CboProvince).html(response);
        },
        error: function(e){
        alert('Error: ' + e);
        }
        });
    
}

function getDistrict(codeCountry , codeDepartment , codeProvince , CboDistrict ){      
       var requestUrl = '/GedeonMvc/district/byprovinceanddepartmentandcountry'   ;
    
              $.ajax({
        type: "POST",
        url: requestUrl,
        data: "codeCountry="+codeCountry+"&codeDepartment="+codeDepartment+"&codeProvince="+codeProvince ,
        success: function(response){  
        $('#'+CboDistrict).html(response); 
        },
        error: function(e){
        alert('Error: ' + e);
        }
        });
}

function validateForm(){
    var message = "";
    if(nameAccount.value == ""){
        message = "Ingrese el Nombre" ;        
    }else if(accountNo.value == ""){
        message = "Ingrse el Ruc";
    }else if(phone.value == ""){
         message = "Ingrese el telefono";
    }else if(foundation.value == ""){
         message = "Ingrese la fecha de fundacion de la empresa"; 
    } else{
     form.submit();     
     return false ;
    }
         
    document.getElementById("bodyMessage").innerHTML = message; 
    return false ;
}

function confirmDelete(record){
   
    $('#id').val(record);  
}

function submitDelete(){
 
    document.getElementById("form").action = 'delete?id='+$('#id').val()+"&module="+$('#module').val();
    document.getElementById("form").submit();  
}

function cloneSelectFacturacion(){//copy from billing to shipping
    
    $('#CboCountryShipping option').remove();
    $('#CboDepartmentShipping option').remove();
    $('#CboProvinceShipping option').remove();
    $('#CboDistrictShipping option').remove();
    
    $('#CboCountryBill').find('option').clone().appendTo('#CboCountryShipping');
    $('#CboDepartmentBill').find('option').clone().appendTo('#CboDepartmentShipping');
    $('#CboProvinceBill').find('option').clone().appendTo('#CboProvinceShipping');
    $('#CboDistrictBill').find('option').clone().appendTo('#CboDistrictShipping');
     
    $('#addressShipping').val($("#addressBill").val());
     $('#emailShipping').val($("#emailBill").val());
    $('select#CboCountryShipping option:selected').val('PER');
     
}

function cloneSelectShipping(){//copy from shipping to billing
    
    $('#CboCountryBill option').remove();
    $('#CboDepartmentBill option').remove();
    $('#CboProvinceBill option').remove();
    $('#CboDistrictBill option').remove();
    
    $('#CboCountryShipping').find('option').clone().appendTo('#CboCountryBill');
    $('#CboDepartmentShipping').find('option').clone().appendTo('#CboDepartmentBill');
    $('#CboProvinceShipping').find('option').clone().appendTo('#CboProvinceBill');
    $('#CboDistrictShipping').find('option').clone().appendTo('#CboDistrictBill');
    
    $('select#CboCountryBill option:selected').val('PER');
    
    $('#addressBill').val($("#addressShipping").val());
    
    $('#emailBill').val($("#emailShipping").val());
     
    
}

function clearCbo(){
//    var texto = document.getElementById("s2id_CboCountryBill").innerHTML;
//    
//    texto = texto.replace('idLinkClose','link_s2id_CboDistrictShipping');
//    
//    document.getElementById("s2id_CboCountryBill").innerHTML =   texto ;
    
    var sAux="";
    
	var frm = document.getElementById("s2id_CboCountryBill");alert(frm.elements.length);
	for (i=0;i<frm.elements.length;i++)
	{
		sAux += "NOMBRE: " + frm.elements[i].name + " ";
		sAux += "TIPO :  " + frm.elements[i].type + " "; ;
		sAux += "VALOR: " + frm.elements[i].value + "\n" ;
	}
    alert(sAux);
//    s2id_CboCountryBill.getElementById('idLinkClose').id = 'cambiado';
//     
//    var valor = "" ;
//    for(i=0; i< CboDistrictShipping.length; i++) { 
//       if( CboDistrictShipping[i].selected) { 
//        valor= CboDistrictShipping.options[i].text; 
//        } 
//    } 
//    
//    texto = texto.replace(valor,'Choose a Department');
//    
//    
//   
//    inner.value = texto ;
////   document.getElementById("s2id_CboDistrictShipping").innerHTML = "ooo"; 
//    
//    document.getElementById('idLinkClose').id = 'cambiado';
   
    alert(valor);
}





$(function() {
  $('#imageFile').change(function(e) {
      
      addImage(e); 
     });
     
   $("#BtnClearData").click(function(){
       $('#imgAccount').attr("src","/GedeonMvc/resources/assets/img/gallery/nopicture.jpg");
       $('#picture').val('no');
   });

$( "#BtnClear" ).click(function() { 
  $('#imgAccount').attr("src","/GedeonMvc/resources/assets/img/gallery/nopicture.jpg");
  $('#picture').val('no');
});

     function addImage(e){
      var file = e.target.files[0],
      imageType = /image.*/;
    
      if (!file.type.match(imageType))
       return;
  
      var reader = new FileReader();
      reader.onload = fileOnload;
      reader.readAsDataURL(file);
     }
  
     function fileOnload(e) {
      var result=e.target.result;
      $('#imgAccount').attr("src",result);
      $('#picture').val('si'); 
     }
    });
 







 
